﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig  
// 
// ---------------------------------------------------------------------
#endregion


#region Usings

using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.Practices.Unity;
using Microsoft.Surface.Presentation.Controls;
using ScrumTable.UI.View.Util;
using ScrumTable.UI.View.WinTouch.UserControls.View;
using ScrumTable.UI.ViewModel;
using ScrumTable.UI.ViewModel.Data;
using ScrumTable.UI.ViewModel.Controller;

#endregion

namespace ScrumTable.UI.View.WinTouch.UserControls.Tool
{
    /// <summary>
    /// Interaction logic for ToolBox.xaml
    /// </summary>
    public partial class ToolBox : ScrumUserControl
    {


        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------
        [Dependency]
        public AppScreen MainScreen { get; set; }

        [Dependency]
        public IUnityContainer Container { get; set; }

        [Dependency]
        public ScrumViewModelData ScrumData { get; set; }

        /// <summary>
        /// DependencyProperty of HideInfo
        /// </summary>
        public static readonly DependencyProperty HideInfoProperty =
          DependencyProperty.Register("HideInfo",
                                      typeof(bool),
                                      typeof(ToolBox),
                                      new UIPropertyMetadata(false));
        /// <summary>
        /// Gets or sets if the info is displayed.
        /// </summary>
        /// <value>if the info is visible</value>
        public bool HideInfo
        {
            get { return (bool)GetValue(HideInfoProperty); }
            set { SetValue(HideInfoProperty, value); }
        }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="ToolBox"/> class.
        /// </summary>
        public ToolBox()
        {
            
                 
            InitializeComponent();
            DataContext = this;
        }

        #endregion

        private void OnOpenProjectPlanningUserStories(object sender, RoutedEventArgs e)
        {
            var control = Container.Resolve<ProjectPlanningUserStories>();
            ShowWindow(control, sender);
        }

        private void OnOpenProjectPlanningIterations(object sender, RoutedEventArgs e)
        {
            var control = Container.Resolve<ProjectPlanningIterations>();
            ShowWindow(control, sender);
        }

        private void OnOpenSprintPlanningTask(object sender, RoutedEventArgs e)
        {
            var control = Container.Resolve<SprintPlanningTask>();
            ShowWindow(control, sender);
        }

        private void OnOpenStackedDailyScrumStoryBoard(object sender, RoutedEventArgs e)
        {
            var control = Container.Resolve<StackedDailyScrumStoryBoard>();
            ShowWindow(control, sender);
        }

        private void OnOpenDailyScrumTaskBoard(object sender, RoutedEventArgs e)
        {
            var control = Container.Resolve<DynamicBoard>();
            control.Config = ElementManager.GetTargetConfig(NavigationTarget.DailyScrumTaskBoard.ToString());
            ShowWindow(control, sender, false);
        }
 
        private void OnOpenDailyScrumStoryBoard(object sender, RoutedEventArgs e)
        {
            var control = Container.Resolve<DynamicBoard>();
            control.Config = ElementManager.GetTargetConfig(NavigationTarget.DailyScrumStoryBoard.ToString());
            ShowWindow(control, sender, false);
        }


        private void ShowWindow(ScrumUserControl control, object sender, bool isSingleItem = true)
        {
            control.Width = MainScreen.ActualWidth * 0.75;
            control.Height = MainScreen.ActualHeight * 0.75;
            MainScreen.AddScatteredItem(control, MainScreen.PointToScreen(new Point(MainScreen.Width * 0.5, MainScreen.Height * 0.5)), true, true, ((Control)sender).ToolTip.ToString(), isSingleItem);
        }

        private void OnShowBurnRate(object sender, RoutedEventArgs e)
        {
            //MainScreen.AddReportImageToScatterItem(Container.Resolve<ScrumViewModelData>().CurrentIteration.BurnRateChartUri);
            var x2 = Container.Resolve<WpfReportSelector>();
            Container.Resolve<AppScreen>().AddScatteredItem(x2, Application.Current.MainWindow.PointToScreen(new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2)), true, true, ((SurfaceButton)sender).ToolTip.ToString(), true);
            /*
            var x2 = Container.Resolve<ReportSelector>();
            Container.Resolve<AppScreen>().AddScatteredItem(x2, Application.Current.MainWindow.PointToScreen(new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2)), true, true, ((SurfaceButton)sender).ToolTip.ToString(), true);
             * */

        }

        private void OnUndo(object sender, RoutedEventArgs e)
        {
            ScrumData.DataContext.UndoManager.Undo();
        }


        private void OnRedo(object sender, RoutedEventArgs e)
        {
            ScrumData.DataContext.UndoManager.Redo();
        }

        private void OnRotate(object sender, RoutedEventArgs e)
        {
            MainScreen.Rotate();
        }

        private void OnAbout(object sender, RoutedEventArgs e)
        {

            var appScreen = Container.Resolve<AppScreen>();
            var about = new AboutDialog();//ScrumUserControl() {Width = 800, Height = 600, Background = Application.Current.Resources["AboutBackground"] as Brush};
            appScreen.AddScatteredItem(about, Application.Current.MainWindow.PointToScreen(new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2)), true);

            /*
            var dialog = new AboutDialog();
            ClickUtil click = new ClickUtil();
            dialog.TouchDown += (a, b) =>
            {
                if (click.IsClickInTime())
                {
                    appScreen.RemoveItem(dialog);
                    dialog.Dispose();
                }
            };

            appScreen.AddItem(dialog, false);*/
        }

        private void OnLogOut(object sender, RoutedEventArgs e)
        {
            ScrumData.Disconnect();
        }


        private void OnChangeLogin(object sender, RoutedEventArgs e)
        {
            var x = Container.Resolve<MemberChangeControl>();
            Container.Resolve<AppScreen>().AddScatteredItem(x,  Application.Current.MainWindow.PointToScreen(new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height - 35)), false, false, null, true);
        }


        private void OnTeamMemberOpen(object sender, RoutedEventArgs e)
        {
            var x = Container.Resolve<TeamMemberSelector>();
            x.Width = 400;
            x.Height = 200;
            Container.Resolve<AppScreen>().AddScatteredItem(x, Application.Current.MainWindow.PointToScreen(new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2)), true, true, null, true);
        }


        private void OnGoToOverView(object sender, RoutedEventArgs e)
        {
            Container.Resolve<ScrumController>().GoTo(NavigationTarget.ScrumMap);
        }

        private void OnSearch(object sender, RoutedEventArgs e)
        {
            var x2 = Container.Resolve<SearchScreen>();
            Container.Resolve<AppScreen>().AddScatteredItem(x2, Application.Current.MainWindow.PointToScreen( new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2) ), true, true, ((SurfaceButton)sender).ToolTip.ToString(), true);
            
        }
        private void OnFilter(object sender, RoutedEventArgs e)
        {
            var x2 = Container.Resolve<FilterBox>();
            Container.Resolve<AppScreen>().AddScatteredItem(x2, Application.Current.MainWindow.PointToScreen( new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2) ), true, false, ((SurfaceButton)sender).ToolTip.ToString(), true);
        }

        private void OnShowUndoRedoHistory(object sender, RoutedEventArgs e)
        {

            var x = Container.Resolve<UndoRedoHistory>();
            Container.Resolve<AppScreen>().AddScatteredItem(x,  Application.Current.MainWindow.PointToScreen(new Point(Application.Current.MainWindow.Width / 2, Application.Current.MainWindow.Height / 2)), true, true, null, true);
            
        }
    }
}
